//Standard Headers
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

//External headers
#include <unistd.h>
#include <sys/ioctl.h>
#include <termios.h>

//Local Headers
#include "cards.h"

/*Notes:
 * exit status 3 = Terminal Size insuficient*/

void verify_terminal_size(void) {
	//see linux manual page ioctl_tty
	struct winsize win;
	ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
	if(win.ws_row < 25 || win.ws_col < 120) {
		printf("Terminal Size insuficient: minimum 50 rows and 120 colums\n");
		exit(3);
	}
}


void draw_card(char *screen, uint8_t x, uint8_t y, cards_ptr *card) {
		//This loops draw the card line
		for(int i = 0; i<10 ; i++) {
			screen[x+y*120+i+1] = '_';
		}
		for(int i = 0; i < 12; i++) {
			if(i == 0 || i == 11) { screen[x+y*120+i] = '|'; }
			else
				screen[x+y*120+i] = ((struct Monster_Card*)card->card)->name[i-1];
		}

}

void draw(char *screen) {
	printf("\033[0;0H");
	printf("\033[2J");
	printf("%s", screen);
}
void input();

void main_Loop();

void main_menu(int *state) {
	printf("1->New Game\n2->Deck Editor\n3->Quit");
	scanf("%d", state);
}

int main(void) {
	
	verify_terminal_size();
	char screen[25*120];
	int state = 0; //1-> MENU, 2-> DECK EDITOR 3-> DUEL
	/*i can use this state to alter the behavior of the
	 *draw and the input function*/
	cards_ptr * test = get_cards();
	draw_card(screen, 0, 0, test);
	draw(screen);
	fgetc(stdin);
	return 0;
}
